package com.work.washer.controller;

import com.work.washer.model.Type;
import com.work.washer.service.TypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@Tag(name = "分类")
@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private TypeService typeService;

    /**
     * 添加
     *
     * @param type
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @Operation(summary = "新增")
    @PostMapping("/save")
    public boolean save(@RequestBody Type type) {
        return typeService.save(type);
    }


    /**
     * 根据主键删除
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @Operation(summary = "删除")
    @GetMapping("/remove/{id}")
    public boolean remove(@PathVariable Integer id) {
        return typeService.removeById(id);
    }


    /**
     * 根据主键更新
     *
     * @param type
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @Operation(summary = "更新")
    @PostMapping("/update")
    public boolean update(@RequestBody Type  type) {
        return typeService.updateById(type);
    }


    /**
     * 查询所有
     *
     * @return 所有数据
     */
    @Operation(summary = "列表")
    @GetMapping("/list")
    public List<Type > list() {
        return typeService.list();
    }


    /**
     * 根据主键获取详细信息。
     *
     * @param id type主键
     * @return 详情
     */
    @Operation(summary = "详情")
    @GetMapping("/getInfo/{id}")
    public Type  getInfo(@PathVariable Integer id) {
        return typeService.getById(id);
    }

}